<template>
    <div class="apppadding bgfff">
        <bDetail :instance="pForm" class="form" title="预约人信息" cover="80%"></bDetail>
    </div>
    <div class="apppadding bgfff">
        <bDetail :instance="pForm" label_prop="labels_info" class="form" title="订单信息" cover="80%"></bDetail>
    </div>
    <div class="blank"></div>
    <div v-if="pForm.data.status === NURSING_APPOINTMENT_STATUS.已审核">
        <Button type="primary" :plain="true" v-if="but.has('nursing_appointment:assign:no')" @click="assignNo">
            {{ but.get('nursing_appointment:assign:no') || '退回' }}</Button>
        <Button type="primary" v-if="but.has('nursing_appointment:assign')" @click="pForm.showAssign = true">
            {{ but.get('nursing_appointment:assign') || '分配' }}</Button>
    </div>
    <Popup v-model:show="pForm.showAssign" title="分配" @open="() => pForm.getNurseOptions()">
        <div v-if="pForm.nurse.length === 0">
            暂无可分配护士
        </div>
        <CheckboxGroup v-else style="flex-grow: 1;display: flex;" v-model="pForm.nurseIds">
            <Checkbox v-for="value in pForm.nurse" :key="value.id" :value="value.id">
                {{ value.name }}
            </Checkbox>
        </CheckboxGroup>
        <template #footer>
            <div class="dialog-footer">
                <Button @click="pForm.showAssign = false">取消</Button>
                <Button type="primary" @click="() => pForm.assign()">分配</Button>
            </div>
        </template>
    </Popup>
</template>

<script lang="ts" setup>
import bDetail from "@m/components/public/b_detail.vue";
import { IForm } from "@b/index/nursing_appointment";
import { useRoute } from "vue-router";
import { pagebuttonStore } from "@b/store";
import { Button, Popup, CheckboxGroup, Checkbox } from "vant";
import bMessageBox from "@m/components/widget/b_message_box";
import { NURSING_APPOINTMENT_STATUS } from "@b/model/enum";

const pForm = new IForm();
const id = useRoute().query.id;
pForm.id = Number(id);
pForm.url.info = '/nursing_appointment/info/lender';
const but = pagebuttonStore().button;
pForm.setData();
pForm.init();

const assignNo = () => {
    bMessageBox('未通过原因', {
        placeholder: '请输入未通过原因',
        title: '退回',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
    }).then((message) => {
        pForm.assignNo(message)
    })
}
</script>
